﻿using Demo.Net.Model;
using IRepository;
using Iservice;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace service
{
    public class BaseService<TEntity> : IBaseService<TEntity> where TEntity : class
    {
        protected IBaseRepository<TEntity> baseRepository;
        //添加
        public async Task<bool> Add(TEntity entity)
        {
            return await baseRepository.Add(entity);
        }
        //删除
        // public async Task<bool> Delete(TEntity entity)
        // {
        //     return await baseRepository.Delete(entity);
        // }
        //删除
        public async Task<bool> Delete(int id)
        {
            return await baseRepository.Delete(id);
        }
        //id查找
        public async Task<List<TEntity>> Find(Expression<Func<TEntity, bool>> exp)
        {
            return await baseRepository.Find(exp);

        }
        //查找全部
        public async Task<List<TEntity>> FindAll()
        {
            return await baseRepository.FindAll();
        }
        //模糊查询
         public async Task<List<TEntity>> FindAllByCondition(System.Linq.Expressions.Expression<Func<TEntity, bool>> searchTerm)
        {
            return await baseRepository.FindAllByCondition(searchTerm);
        }
        //更新
        public async Task<bool> UpdateAsync(TEntity entity)
        {
            return await baseRepository.UpdateAsync(entity);
        }

    }
}
